package com.hudongwx.godoffood.activity.myActivity;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.hudongwx.godoffood.R;
import com.hudongwx.godoffood.utils.MyApplication;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.x;

import java.util.HashMap;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.tencent.qq.QQ;

@ContentView(R.layout.activity_service)
public class ServiceActivity extends AppCompatActivity {
    private String TAG="ServiceActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
    }

    @Event(R.id.more_service_qq)
    private void intentQQ(View view){
        ShareSDK.initSDK(this);
        Platform QQPlatform= ShareSDK.getPlatform(QQ.NAME);
        //因为登录成功以后，就不会再次登录，为了演示，我在登录之前，移除授权
        QQPlatform.removeAccount(true);

        QQPlatform.setPlatformActionListener(new PlatformActionListener() {
            @Override
            public void onComplete(Platform platform, int i, final HashMap<String, Object> hashMap) {
                Log.i(TAG, "onComplete: "+hashMap.toString());
                //在ui线程提示
                ServiceActivity.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(ServiceActivity.this,"登录成功："+hashMap.get("nickname"),Toast.LENGTH_SHORT).show();
                        ServiceActivity.this.finish();
                    }
                });
            }

            @Override
            public void onError(Platform platform, int i, Throwable throwable) {
                Log.i(TAG, "onError: "+throwable.getMessage());
            }

            @Override
            public void onCancel(Platform platform, int i) {
                Log.i(TAG, "onCancel: "+platform.getName());

            }
        });
//authorize与showUser单独调用一个即可
//        QQPlatform.authorize();//单独授权,OnComplete返回的hashmap是空的
        QQPlatform.showUser(null);//授权并获取用户信息
//移除授权
//weibo.removeAccount(true);
    }
    //跳到拨号界面
    @Event(R.id.more_service_tel)
    private void intentTel(View view){
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        View inView = getLayoutInflater().inflate(R.layout.my_exit_login_dialog, null);
        builder.setView(inView);
        TextView tvTitle = (TextView) inView.findViewById(R.id.exit_login_tv_title);
        tvTitle.setText("你确定要拨打这个电话？");
        TextView tvCancel = (TextView) inView.findViewById(R.id.exit_login_tv_cancel);
        TextView tvYes = (TextView) inView.findViewById(R.id.exit_login_tv_yes);

        final AlertDialog dialog = builder.show();
        //弹窗取消
        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        //确定取消登陆状态  回恢复以前的状态并且关闭窗口
        tvYes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent= new Intent();
                intent.setAction(Intent.ACTION_DIAL);
                Uri uri = Uri.parse("tel://4006230106");
                intent.setData(uri);
                startActivity(intent);
                dialog.dismiss();
            }
        });


    }
    //返回拦截
    @Event(R.id.my_service_iv_back)
    private void back(View view){
        finish();
    }
}
